package com.dev.view.tab1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dev.R;
import com.dev.bean.FragmentTab1Response;
import com.dev.view.common.adapter.CommonBaseAdapter;

/**
 * Created by self on 16/6/15.
 */
public class FragmentTab1Adapter extends CommonBaseAdapter<FragmentTab1Response> {

    private Context context;

    public FragmentTab1Adapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public View newView(Context context, FragmentTab1Response response, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.fragment_tab1_adapter_item, parent, false);
        ViewHolder holder = new ViewHolder(convertView);
        convertView.setTag(holder);
        return convertView;
    }

    @Override
    public void bindView(int position, View convertView, FragmentTab1Response response) {
        ViewHolder holder = (ViewHolder) convertView.getTag();

        holder.img_icon.setImageResource(response.img_icon);
        holder.tv_name.setText(response.tv_name);
        holder.tv_content.setText(response.tv_content);
    }

    static class ViewHolder {
        ImageView img_icon;
        TextView tv_name;
        TextView tv_content;

        public ViewHolder(View view) {
            img_icon = (ImageView) view.findViewById(R.id.img_icon);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            tv_content = (TextView) view.findViewById(R.id.tv_content);
        }
    }

}
